package com.future.account.controller;

import com.alibaba.fastjson.JSONObject;
import com.future.config.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 账号信息控制器
 *
 * @author shiyong
 * 2022/2/16 9:15
 */
@RestController
@RequestMapping("/accountInfo")
@Slf4j
public class AccountInfoController {

    /**
     * 新增账号
     *
     * @param accountName 账号名称
     * @return com.alibaba.fastjson.JSONObject
     * @author shiyong
     * 2022/2/16 9:24
    */
    @PostMapping("/addAccount")
    public JSONObject addAccount(String accountName) {
        log.info("创建账号：" + accountName);

        JSONObject result = new JSONObject();
        result.put("accountName", accountName);
        result.put("createTime", LocalDateTime.now());
        return result;
    }

    /**
     * 删除账号
     *
     * @param accountName 账号名称
     * @author shiyong
     * 2022/3/10 12:18
    */
    @PostMapping("/deleteAccount")
    public void deleteAccount(String accountName) {
        log.info("删除账号：" + accountName);

        throw new BusinessException("删除账号失败，账号：" + accountName + "不存在");
    }
}
